<?php
defined('IN_YuLin') || exit('NO PERMIT!');

$table         = Table('web_bank');
$bindBankTable = Table('user_bank');
$webBank       = Table('web_bank');
$uid           = $_SESSION['uid'];
if (!$uid){
    return;
}
// 获取操作标识
$op    = $_GET['op'];
// 条件
$where = ' FROM ' .$table . ' WHERE status = 1';
$tmp   = '';
if (IS_POST){
    // 如果当前该用户已经绑定了5条信息，则添加失败
    $checkMaxSql     = 'SELECT COUNT(1) as cnt FROM ' . $bindBankTable . ' WHERE uid = ' . $uid . ' AND status = 1';
    $bindNum         = $db->getrow($checkMaxSql);
    if ($bindNum['cnt'] >= 5){
        return;
    }
    $js              = explode('-', NoBadStr($_REQUEST['account_city']));
    $ins['uid']      = $_SESSION['uid'];
    $ins['truename'] = NoBadStr($_REQUEST['account_name']);
    $ins['bank']     = NoBadStr($_REQUEST['account_bankid']);
    $ins['bankcard'] = NoBadStr($_REQUEST['account_num']);
    $ins['province'] = $js[0];
    $ins['city']     = $js[1];
    $ins['security'] = md5(NoBadStr($_REQUEST['account_password']));
    $ins['dateline'] = time();
    $ins['status']   = '1';
    $flag = $db->exec('INSERT INTO '.$bindBankTable.CreateInsertSql($ins));
    if ($flag){
        AjaxReturn(['error'=>'0','msg'=>'操作成功']);
    }else{
        AjaxReturn(['error'=>'1','msg'=>'操作失败']);
    }
}

// 获取所有银行类别信息列表
$bankList  = $db->getall('SELECT * ' . $where);
$bankIdKey = array();
foreach ($bankList as $bk => $bv){
    $bankIdKey[$bv['id']] = $bv;
}
switch ($op){
    case 'bindcard':
        $tmp = 'member/bankCard_add';
        break;
    case 'unbindcard':
        $id  = NoBadStr($_REQUEST['id']);
        $upd = array('status' => 0);
        $flag = $db->exec('UPDATE ' . $bindBankTable . ' SET ' . CreateUpdateSql($upd) . ' WHERE id = ' . $id);
        if ($flag){
            AjaxReturn(['error'=>'0','msg'=>'操作成功']);
        }else{
            AjaxReturn(['error'=>'1','msg'=>'操作失败']);
        }
        break;
    default:
        $tmp = 'member/bankCard_manage';
        break;
}
$tpl->display($tmp);
?>